const VERIFY_CODE = [
    "1", '2', '3', '4', '5', '6', '7', '8', '9',
    "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
    "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
    "a", "b", "c", "d", "e", "f", "g", 'h', 'i', 'j', 'k', 'l', 'm',
    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
]

export function random(max = 10): number {
    return Math.floor(Math.random() * max)
}

export function generateVerifyCode(): string[] {
    const code = []
    for (let i = 0; i < 4; i++) {
        code.push(VERIFY_CODE[random(61)])
    }
    return code
}

const TOKEN_KEY = "__PM_TOKEN_KEY__"

export function setToken(token: string) {
    window.localStorage.setItem(TOKEN_KEY, token)
}

export function getToken(): string {
    const raw = window.localStorage.getItem(TOKEN_KEY)
    if (!raw) {
        return ""
    }
    return raw
}

//  格式化函数
export function formatDate(date: Date, min = "day") {
    const day = date.getDate()
    const month = date.getMonth() + 1
    const year = date.getFullYear()

    return `${year}/${month}/${day}`
}


export function parseTimestamp(date: Date) {
    return date.getTime()
}
